<template>
  <div>
    <FormPanel :list="topFilterList" :cols="3" :labelWidth="100" :collapse="false" :isSubmitBtn="false" />
    <FilterTable
      ref="mainTable"
      :columns="tableColumns"
      columnsRef="aduitOrder"
      :datakey="'records'"
      selectionType="single"
      :dataSource="dataSource"
      :isSelectColumn= false
      :onColumnsChange="columns => (this.tableColumns = columns)"
    >
    </FilterTable>


    <FilterTable
      ref="mainTable2"
      :columns="tableColumns2"
      columnsRef="aduitOrder"
      :datakey="'records'"
      selectionType="single"
      :dataSource="dataSource2"
      :isSelectColumn= false
      :onColumnsChange="columns => (this.tableColumns2 = columns)"
    >
    </FilterTable>

    <div class="dialogBottmView">

      <el-button  v-show="this.isShow" type="primary" icon="el-icon-tickets" :loading="loading"
                   @click="aduit(10041001)" vertical-align = "middle">审核通过
                   </el-button>

      <el-button  v-show="this.isShow" size="small" type="primary" icon="el-icon-tickets" :loading="loading"
                   @click="refuByPurchase" vertical-align = "middle">审核驳回
                   </el-button>
      <el-button @click="closeDialogTop">返 回</el-button>

    </div>





    <BaseDialog v-if="visible" :visible.sync="visible" title="审核" width="40%" show-close="false">

                  <span>
                    驳回原因
                    <el-input
                      width="25%"
                      v-model="aduitRem"
                      placeholder="请输入"
                    ></el-input>
                  </span>

                  <br />
                  <br />
                  <span class="dialog-footer">
                    <el-button type="primary" @click="aduit(10041002)">确 定</el-button>
                    <el-button type="primary" @click="visible=false">取 消</el-button>
                  </span>

    </BaseDialog>




  </div>
</template>
<script>
import { partbuyStockInItemOEM,auditBoOrder,aduitBoPocess } from '@/api/partsmanage/aduitOrder/index';
import { dictionary } from '@/utils/dictMixin';
import { byAllInfo } from '@/api/part/allocation';
import { getStorageList, querySysParam } from '@/api/part/common';

export default {
  name: 'partBuyItems',
  props: {
    // top:{}
    value: {
      type: Object,
      data: Object,
    }
  },
  mixins: [dictionary],
  data() {
    return {
      isShow:false,
      type: this.value.type,
      topFilterList: this.createTopFilterList(),
      tableColumns: this.createTableColumns(),
      tableColumns2: this.createTableColumns2(),
      fetchParams: {},
      dataSource: [],
      dataSource2: [],
      storageDic: [
        { text: 'OEM电', value: 'OEM-ELECTIC' },
        { text: 'OEM油', value: 'OEM-OIL' }
      ], // 仓库字典
      visible: false,
      loading: false,
      aduitRem:'',


    };
  },
  mounted() {
    // this.translate(this.top.CUSTOMER_CODE);
    // this.getStorage();
    this.findBuyItems();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '服务站代码',
          fieldName: 'DEALER_CODE',
          initialValue: '',

          disabled: true
        },
        {
          type: 'INPUT',
          label: '服务站名称',
          fieldName: 'DEALER_NAME',
          initialValue: '',

          disabled: true
        },
        {
          type: 'INPUT',
          label: '采购单号',
          fieldName: 'XSDDHM',
          initialValue: '',

          disabled: true
        },
        // {
        //   type: 'INPUT',
        //   label: '备注',
        //   initialValue: '',

        //   fieldName: 'XSDDBZ',
        //   placeholder: '请输入...',
        //   disabled: true
        // },
        {
          type: 'INPUT',
          label: '销售单号',
          fieldName: 'SAP_NO',
          initialValue: '',

          disabled: true
        },
        {
          type: 'SELECT',
          label: '订单类型',
          initialValue: '',

          fieldName: 'XSDDLX',
          itemList: this.createDictList('3003'),

          disabled: true
        },
        {
          type: 'DATE',
          fieldName: 'BOQXSJ',
          initialValue: '',

          label: 'BO上报日期',
          dateFormat: 'yyyy-MM-dd',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '上报人',
          initialValue: '',

          fieldName: 'TB_MAN',
          placeholder: '请输入...',
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '取消原因',
          initialValue: '',
          selfCols: 2,
          maxlength: 1000,
          fieldName: 'CLOSE_REASON',
          placeholder: '请输入...',
          disabled: true
        }

      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          // sorter: true,
          width: 70,
          dataIndex: 'xuhao',
          sorter: true,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          },
          sorter: true
        },
        {
          title: '备件代码',
          width: 180,
          sorter: true,
          dataIndex: 'BJXMBH',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件名称',
          width: 180,
          sorter: true,
          dataIndex: 'BJZWMC',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '单位',
          width: 180,
          sorter: true,
          dataIndex: 'BJDANW',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '最小包装量',
          sorter: true,
          dataIndex: 'SALES_PACK_NUM',
          precision: 2,
          filter: true,
          filterType: 'number',
          min: 0,
          max: Infinity,
          widht: 130
        },
        {
          title: '最小订购量',
          sorter: true,
          dataIndex: 'IN_SERVICE_AMOUNT',
          precision: 2,
          filter: true,
          filterType: 'number',
          min: 0,
          max: Infinity,
          widht: 130
        },
        {
          title: '采购单价',
          sorter: true,
          dataIndex: 'XSYSJE_AMOUNT',
          precision: 2,

          filter: true,
          filterType: 'number'
        },
        {
          title: '采购数量',
          sorter: true,
          dataIndex: 'BSTXSL',
          precision: 2,
          summation: true,
          filter: true,
          filterType: 'number',
          min: 0,
          max: Infinity,
          widht: 130
        },
        {
          title: '采购金额',
          sorter: true,
          dataIndex: 'XSYSJE',
          precision: 2,
          summation: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '受理数量',
          sorter: true,
          dataIndex: 'NOBO_NUM',
          precision: 2,
          filter: true,
          filterType: 'number',
          min: 0,
          max: Infinity,
          widht: 130
        },
        {
          title: '未受理数量',
          sorter: true,
          dataIndex: 'BO_NUM',
          precision: 2,
          filter: true,
          filterType: 'number',
          min: 0,
          max: Infinity,
          widht: 130
        },
        {
          title: '取消数量',
          sorter: true,
          dataIndex: 'QXSL',
          precision: 2,
          filter: true,
          filterType: 'number',
          min: 0,
          max: Infinity,
          widht: 130
        },
        {
          title: '是否闭环',
          dataIndex: 'ISBODD',
          sorter: true,
          render: props => { return <span>{this.createDictText(props.row.bjpjsx, '1004')}</span>; }
        },
        { title: '闭环时间',
         dataIndex: 'BOQRSJ',
         sorter: true,
         dateFormat: 'yyyy-MM-dd HH:mm:ss',
        },

      ];
    },

    createTableColumns2() {
      return [
        {
          title: '序号',
          // sorter: true,
          width: 70,
          dataIndex: 'xuhao',
          sorter: true,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          },
          sorter: true
        },
        {
          title: '审核人',
          width: 180,
          sorter: true,
          dataIndex: 'UPDATED_BY',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '审核时间',
          width: 180,
          sorter: true,
          dataIndex: 'AUDIT_TIME',
          showOverflowTooltip: true,
          dateFormat: 'yyyy-MM-dd',
          filter: true,
          sorter: true,
          filterType: 'date-range'
        },
        {
          title: '审核状态',
          sorter: true,
          dataIndex: 'AUDIT_TYPE',
          precision: 2,
          filter: true,
          filterType: 'number',
          min: 0,
          max: Infinity,
          widht: 130
        },

        {
          title: '审核说明',
          sorter: true,
          dataIndex: 'AUDIT_REM',
          precision: 2,
          filter: true,
          filterType: 'number'
        },
      ];
    },
    //  changeSelect() {
    //         this.form.tableData = [];

    //     },

    refuByPurchase() {
      this.aduitRem = null;
      this.visible = true


    },
    closeDialogTop(){
       this.$emit('cancel',false);
    },
    aduit(e) {

          // console.log('this.form ============ :'+ JSON.stringify(this.form));
          auditBoOrder({
              id: this.value.data.ID,
              type:e,
              aduitRem:this.aduitRem
          }).then(res => {
              if(res.success){
              this.$notify.success('审核成功!');
              // 请求执行成后，刷新主页面子表格
              this.$emit('cancel',true);
            }else{
              this.$notify.error(res.errMsg);

            }
          });

    },

    // async translate(dealerCode) {
    //   let name = '';
    //   let res = await byAllInfo({ dealerCode: dealerCode });
    //   if (res.resultCode == 200 && res.data && res.data.records && res.data.records.length > 0) {
    //     name = res.data.records[0].companyName;
    //   }
    //   this.topFilterList.find(x => x.fieldName == 'ownerName').initialValue = name;
    // },
    // async getStorage() {
    //   const ckRes = await getStorageList();
    //   const ckDict = ckRes.data.map(x => ({ text: x['STORAGE_NAME'], value: x['STORAGE_CODE'] }));
    //   this.storageDic = ckDict;
    //   this.tableColumns.find(x => x.dataIndex == 'STORAGE_CODE').filterItems = this.tableColumns.find(x => x.dataIndex == 'STORAGE_CODE').dictItems = ckDict;
    // },
    async findBuyItems() {


      console.log('this.form ++++++++ :'+ JSON.stringify(this.topFilterList));
      this.topFilterList.map(x => {
        let ss = x.fieldName;
        x.initialValue = this.value.data[x.fieldName];
        // x.initialValue = this.top[x.fieldName];
      });

      if(this.value.type != 'show'){
          this.isShow = true


      }

      console.log('this.form ============ :'+ JSON.stringify(this.value.data));



      let res = await partbuyStockInItemOEM({ partOrderId: this.value.data.ID });
      // console.log('this.form ============ :'+ JSON.stringify(res));
      this.dataSource = res.data;

      let res2 = await aduitBoPocess({ partOrderId: this.value.data.ID });
      // console.log('this.form ============ :'+ JSON.stringify(res));
      this.dataSource2 = res2.data;
    }
  }
};
</script>
